package com.xplay.xpocker.controller;

import com.xplay.xpocker.config.ResultFul;
import com.xplay.xpocker.observer.ChannelHandlerManager;
import com.xplay.xpocker.room.message.MessageContent;
import com.xplay.xpocker.util.JacksonStringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * @author wanjie
 * @date 2021/3/17 20:36
 */
@RestController
@RequestMapping(value = "open/room", produces = "application/json;charset=UTF-8")
public class RoomTestController {
    private static final Logger logger = LoggerFactory.getLogger(RoomTestController.class);


    @PostMapping(value = "message")
    public ResultFul addRoom(@RequestBody HashMap<String, Object> data) {
        // 房间内所有的消息 统一处理
        // 找到用户所属房间号 顶层类型  1 语音   2   消息 统一处理  3  事件   内部消化
        // 按照类型处理
        String dataStr = JacksonStringUtil.objectToString(data, false);
        MessageContent<?> content = JacksonStringUtil.objectCase(dataStr, MessageContent.class);
        ChannelHandlerManager.getInstance().notifyMessage(content);
        return ResultFul.ok(true);
    }

}
